package com.centling.smartSealForPhone.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

/**
 * @author fionera
 */
public class DbHelper extends SQLiteOpenHelper {

    private static final int VERSION = 3;

    private DbHelper(Context context, String name, SQLiteDatabase.CursorFactory factory,
                     int version) {
        super(context, name, factory, version);
    }

    private DbHelper(Context context, String name, int version) {
        this(context, name, null, version);
    }

    DbHelper(Context context, String name) {
        this(context, name, VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        //创建数据库sql语句
        String sql = "create table image( _id INTEGER PRIMARY KEY AUTOINCREMENT,type varchar(4),task_id varchar(40),user_id varchar(40),back_id varchar(200),company_code varchar(200),paths varchar(100),date varchar(20))";
        String sql2 ="create table local( _id INTEGER PRIMARY KEY AUTOINCREMENT,processFlag varchar(20),processId varchar(20),alarmMsg varchar(20),latitude varchar(20),longitude varchar(20) ,alarmLocation varchar(20),company_code varchar(200))";
        String sql3 ="create table user( _id INTEGER PRIMARY KEY AUTOINCREMENT,username varchar(20),telephone varchar(20))";
        db.execSQL(sql);
        db.execSQL(sql2);
        db.execSQL(sql3);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("drop table if exists image");
        db.execSQL("drop table if exists device_user");
        db.execSQL("drop table if exists name_number");
        onCreate(db);
        Log.e("更新数据库成功", oldVersion + "---" + newVersion);
    }
}
